<?
function setComplete($id) {
	global $AppUI;

	$task = new CTask();
	if ($task->load($id)) {
		$q = new DBQuery();
		$q->addTable('user_tasks');
		$q->addQuery('user_id');
		$q->addWhere('task_id = '.$id);
		$q->addWhere('user_id = '.$AppUI->user_id);
		$r = $q->loadResult();
		if ($r != $AppUI->user_id) {
			$p = new CProject($task->task_project);
			if (!$p->project_id || $p->getManager() != $AppUI->user_id) {
				return 'Error';
			}
		}
		$q->addTable('tasks');
		$q->addUpdate('task_percent_complete', '100');
		$q->addWhere('task_id = '.$id);
		$q->exec();
		return 'OK';
	}
	return 'Error';
}

$id = $_REQUEST['task_id'];
if (defined('DP_BASE_DIR') && isset($id)) {
	echo setComplete($id);
}
else {
	echo 'You should not call this file directly';
}
?>
